package com.zzzfwd.menuhelper

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider

class ResultActivity : AppCompatActivity() {

    companion object {
        private const val CONFIGURATION_SHARED_PREF = "configuration_shared_pref"
    }

    private lateinit var menuViewModel: MenuViewModel

    private val resultView: TextView by lazy { findViewById(R.id.result_view) }
    private val shuffleBtn: Button by lazy { findViewById(R.id.shuffle_btn) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_result)

        val sharedPreferences = getSharedPreferences(CONFIGURATION_SHARED_PREF, MODE_PRIVATE)
        menuViewModel =
            ViewModelProvider(
                this,
                MenuViewModelFactory(sharedPreferences)
            )[MenuViewModel::class.java]

        shuffleBtn.setOnClickListener {
            val result = menuViewModel.generateResult()
            resultView.text = result
        }

        val result = menuViewModel.generateResult()
        resultView.text = result
    }
}